package com.dcy.znoa.controller.publiz;

import com.dcy.znoa.common.annotation.AuthenticationAPI;
import com.dcy.znoa.common.controller.BaseController;
import com.dcy.znoa.common.exception.BusinessException;
import com.dcy.znoa.common.util.pojo.JsonCommon;
import com.dcy.znoa.domain.OperSession;
import com.dcy.znoa.service.software.SessionService;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class LoginController extends BaseController {

    @Autowired
    SessionService sessionService;

    @ResponseBody
    @RequestMapping("/login")
//    @ApiOperation(value = "根据手机号码、密码及推送ID登录", httpMethod = "GET", response = JsonCommon.class, notes = "登录系统")
    public JsonCommon login(String mobile, String password,String pushId) throws BusinessException{
        OperSession operSession =  sessionService.login(mobile, password, pushId);
        return new JsonCommon(operSession);
    }

    @ResponseBody
    @RequestMapping("/logout")
    @AuthenticationAPI
    public JsonCommon login() throws BusinessException{
        sessionService.logout(getCurrentSession());
        return JsonCommon.SUCCESS;
    }
}
